unit Con_LocalCobranca;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, Grids, DBGrids, StdCtrls, Buttons, ExtCtrls,
  Db, DbTables, TFlatButtonUnit;

type
  TFrmCon_LocalCobranca = class(TFrmConsulta)
    Label1: TLabel;
    edtdescricao: TEdit;
    dbgLocalCobranca: TDBGrid;
    btnGravar: TFlatButton;
    procedure BtnFecharClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure edtdescricaoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure btnGravarClick(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    Local_Codigo: string;
  end;

var
  FrmCon_LocalCobranca: TFrmCon_LocalCobranca;

implementation
uses Dm, Biblio, clsLocalCobranca, Cad_LocalCobranca, menu;

{$R *.DFM}

var
  LocalCobranca: TLocalCobranca;
  tds: Tdatasource;
  tq: Tquery;

procedure TFrmCon_LocalCobranca.BtnFecharClick(Sender: TObject);
begin
  inherited;
  Local_codigo := tq.fieldbyname('Local_Codigo').asstring;
  tds.free;
  tq.free;
end;

procedure TFrmCon_LocalCobranca.FormActivate(Sender: TObject);
begin
  inherited;
  if FileExists(caminho_personal + 'belquimica') then begin
    btnGravar.Visible := False;
  end;
  tds := TDataSource.create(FrmCon_LocalCobranca);
  tq := Tquery.create(FrmCon_LocalCobranca);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tds.DataSet := tq;
  fazconsulta;
  edtdescricao.setfocus;
end;

procedure TFrmCon_LocalCobranca.edtdescricaoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then begin
    FazConsulta;
    edtdescricao.setfocus;
  end;
end;

procedure TfrmCon_LocalCobranca.FazConsulta;
begin
  if edtdescricao.text = '' then
    edtdescricao.text := ' ';
  LocalCobranca := TLocalCobranca.Create;
  LocalCobranca.Consultar(tq, edtdescricao.text);
  tq.open;
  LocalCobranca.free;
  dbgLocalCobranca.DataSource := tds;
  dbgLocalCobranca.Refresh;
end;

procedure TFrmCon_LocalCobranca.btnGravarClick(Sender: TObject);
var
  f1: TfrmCad_LocalCobranca;
begin
  inherited;
  f1 := TfrmCad_LocalCobranca.Create(Self);
  f1.btnC_LocalCobranca.Visible := False;
  f1.ShowModal;
  f1.Free;
  FazConsulta;
end;

end.
